package com.leapp;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.LinearLayout;
import android.widget.TableLayout.LayoutParams;
import android.widget.TextView;

public class QuestaoMultiplaActivity extends Activity {

	private LinearLayout l;
	private TextView enunciado;
	private Button botao;
	private ArrayList<CheckBox> checkBoxes = new ArrayList<CheckBox>();
	private Context context;
	Questionario questionario =Questionario.getInstancia();
	private PassadorDeQuestao p = new PassadorDeQuestao();
	private Intent proxima_questao;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context = getBaseContext();
		//Recupera informações das questões
		final Bundle qinfo = getIntent().getExtras();

		l= new LinearLayout(this);
		l.setOrientation(LinearLayout.VERTICAL);
		l.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		enunciado = new TextView(this);
		enunciado.setText(qinfo.getString("com.leapp.enunciado"));
		botao = new Button(this);
		botao.setText("Confirmar");
		botao.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
		l.addView(enunciado);
		
		//Coloca as alternativas
		CheckBox aux;
		for(String item : qinfo.getStringArrayList("com.leapp.listaItens")){
			aux = new CheckBox(this);
			aux.setText(item);
			checkBoxes.add(aux);
			l.addView(aux);
		}
		
		l.addView(botao);
		
		//Click listener do botao
		botao.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				//Tratar a resposta
				
				//Passar a questão
				proxima_questao = p.mostrarProximaQuestao(context, qinfo.getInt("com.leapp.numero"));
				startActivity(proxima_questao);
			}
		});
		
		setContentView(l);
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.questao_multipla, menu);
		return true;
	}

}
